﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.consts.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.track.*;
    import com.tudou.home.view.*;
    import flash.geom.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdBackgroundCommand extends SimpleCommand
    {

        public function AdBackgroundCommand()
        {
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_5:IAdItemInfo = null;
            var _loc_6:Rectangle = null;
            var _loc_2:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            var _loc_3:* = facade.retrieveProxy(AdBackgroundProxy.NAME) as AdBackgroundProxy;
            var _loc_4:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            var _loc_7:* = param1.getBody();
            var _loc_8:int = 0;
            switch(param1.getName())
            {
                case AdBackgroundCommandSet.START:
                {
                    _loc_5 = _loc_2.getAdItemByType(AdType.BACKGROUND);
                    if (_loc_5)
                    {
                        _loc_3.adItemInfo = _loc_5;
                        _loc_3.adThrowInfo = _loc_2.throwInfo;
                    }
                    startBg();
                    break;
                }
                case AdBackgroundCommandSet.CLEAR:
                {
                    _loc_8 = AdModStatus.CLEAR;
                    break;
                }
                case ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE:
                {
                    _loc_6 = PlayerConsts.FULLSCREEN_RECT;
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_6 = PlayerConsts.NORMALSCREEN_RECT;
                        _loc_3.view.goTransform(_loc_6.width, _loc_6.height, false);
                    }
                    break;
                }
                case ViewCommandSet.NORMALSCREEN_RESIZE:
                {
                    startBg();
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_6 = PlayerConsts.NORMALSCREEN_RECT;
                        _loc_3.view.goTransform(_loc_6.width, _loc_6.height, false);
                    }
                    break;
                }
                case ViewCommandSet.EXPAND_STAGE:
                {
                    if (_loc_3 && _loc_3.view)
                    {
                        if (!_loc_7)
                        {
                            startBg();
                        }
                        _loc_3.view.isExpand = _loc_7;
                    }
                    break;
                }
                case AdBackgroundCommandSet.ERROR_END:
                {
                    _loc_8 = AdModStatus.ERROR_END;
                    break;
                }
                case AdBackgroundCommandSet.PREPARE_TO_SHOW:
                {
                    _loc_3.startView();
                    if (_loc_3 && _loc_3.view)
                    {
                        _loc_4.setAdBg(_loc_3.view.adDisplay);
                    }
                    break;
                }
                case AdBackgroundCommandSet.SHOW_START:
                {
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            switch(_loc_8)
            {
                case AdModStatus.ERROR_END:
                case AdModStatus.CLEAR:
                {
                    _loc_3.clearAd();
                    _loc_4.removeAdBg();
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        private function startBg() : void
        {
            var _loc_1:* = facade.retrieveProxy(AdBackgroundProxy.NAME) as AdBackgroundProxy;
            var _loc_2:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            if (ViewState.NORMAL == PageInfo.getInstance().viewState && _loc_2.hasReady)
            {
                if (!AdConsts.BACKGROUND_EXPECTED)
                {
                    AdConsts.BACKGROUND_EXPECTED = true;
                    ADTrackSender.getInstance().adExpect(AdType.BACKGROUND);
                }
                if (_loc_1.adItemInfo)
                {
                    _loc_1.startAd();
                }
            }
            return;
        }// end function

    }
}
